cmake_minimum_required(VERSION 3.19)
project(chassis)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(spdlog REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(asio-driver REQUIRED)
find_package(control-algorithm REQUIRED)
find_package(general_interface REQUIRED)
find_package(tf2 REQUIRED)

add_executable(chassis
  src/chassis.cpp
  src/recorder.cpp)
target_link_libraries(chassis
  asio_driver
  asio_driver_special
  spdlog::spdlog
  control_algorithm)
target_include_directories(chassis PUBLIC include)

add_executable(chassis_aix2
  src/chassis_aix2.cpp
  src/recorder.cpp)
target_link_libraries(chassis_aix2
  asio_driver
  asio_driver_special
  spdlog::spdlog
  control_algorithm)
target_include_directories(chassis_aix2 PUBLIC include)

add_executable(chassis_control
  src/chassis_control.cpp)
target_link_libraries(chassis_control
  asio_driver
  asio_driver_special
  control_algorithm)
ament_target_dependencies(chassis_control
  rclcpp
  general_interface)
install(TARGETS chassis_control DESTINATION lib/${PROJECT_NAME})

add_executable(chassis_dc src/chassis_dc.cpp)
target_link_libraries(chassis_dc asio_driver asio_driver_special)
install(TARGETS chassis_dc DESTINATION lib/${PROJECT_NAME})

add_executable(connection_control src/connection_control.cpp)
target_link_libraries(connection_control asio_driver asio_driver_special)
ament_target_dependencies(connection_control rclcpp rclcpp_action general_interface)
install(TARGETS connection_control DESTINATION lib/${PROJECT_NAME})

add_executable(chassis_server src/chassis_server.cpp)
target_link_libraries(chassis_server asio_driver asio_driver_special)
ament_target_dependencies(chassis_server rclcpp std_msgs sensor_msgs tf2)
install(TARGETS chassis_server DESTINATION lib/${PROJECT_NAME})

# Install Python scripts
ament_python_install_package(${PROJECT_NAME})
install(
  PROGRAMS
  scripts/connection_input_cli.py
  scripts/connection_input_ui.py
  DESTINATION lib/${PROJECT_NAME}
)

# Install launch files
install(
  DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch
)

ament_package()